package com.qiguliuxing.dts.db.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import com.qiguliuxing.dts.db.dao.DtsGoodsAttributeMapper;
import com.qiguliuxing.dts.db.domain.DtsGoodsAttribute;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class DtsGoodsAttributeService {
	@Resource
	private DtsGoodsAttributeMapper goodsAttributeMapper;

	public List<DtsGoodsAttribute> queryByGid(Integer goodsId) {
		QueryWrapper<DtsGoodsAttribute> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(DtsGoodsAttribute::getGoodsId, goodsId);
		queryWrapper.eq("deleted", false);
		return goodsAttributeMapper.selectList(queryWrapper);
	}

	public void add(DtsGoodsAttribute goodsAttribute) {
		goodsAttribute.setAddTime(LocalDateTime.now());
		goodsAttribute.setUpdateTime(LocalDateTime.now());
		goodsAttributeMapper.insert(goodsAttribute);
	}

	public DtsGoodsAttribute findById(Integer id) {
		return goodsAttributeMapper.selectById(id);
	}

	public void deleteByGid(Integer gid) {
		QueryWrapper<DtsGoodsAttribute> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(DtsGoodsAttribute::getGoodsId, gid);
		goodsAttributeMapper.delete(queryWrapper);
	}
}
